package com.czl.module_storehouse.adapter;

import androidx.annotation.NonNull;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.czl.base.data.bean.tengyun.LocatListBean;
import com.czl.module_storehouse.R;

/**
 * @author by xubin,
 * @date on 2022/2/17.
 * PS: Not easy to write code, please indicate.
 */
public class SelectedSortAdapter extends BaseNumAdapter<LocatListBean> {

    private String mTitle;

    public SelectedSortAdapter(int layoutResId) {
        super(layoutResId);
    }

    public void setTitle(String title) {
        mTitle = title;
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, LocatListBean item) {
        item.setCount(item.getAddNumByType());
        super.convert(helper, item);
        helper.setText(R.id.tv_title, item.getStorehouseLocatName())
                .setText(R.id.tv_num_stock, String.valueOf(item.getStockNumInt()))
                .setText(R.id.text_receive, getContext().getString(R.string.risk_placeholder, mTitle));
    }

    @Override
    public int getMaxCount(LocatListBean item) {
        int count = maxCount - LocatListBean.getAddNum(getData(), item);
        return Math.min(count, item.getStockNumInt());
    }

    @Override
    public int getMinCount(LocatListBean item) {
        return 0;
    }

    @Override
    protected void setAfterTextChanged(BaseViewHolder helper, LocatListBean bean, int count) {
        if (bean != null) {
            bean.setStorageNum(count);
            bean.setShiftNum(count);
            bean.setAddNum(count);
            bean.setShiftLocatOut(String.valueOf(bean.getStorehouseLocatId()));
        }
    }
}
